package com.ysh.smartplatform.controller;

import com.ysh.smartplatform.dto.R;
import com.ysh.smartplatform.service.LoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 袁胜虎 on 2022/9/10 18:34
 */
@RestController
@RequestMapping("/logins")
@Api(tags = "登录日志管理")
public class LoginLogController {
    private LoginLogService loginLogService;

    @Autowired
    public void setLoginLogService(LoginLogService loginLogService) {
        this.loginLogService = loginLogService;
    }

    @GetMapping("/login/{loginName}")
    public R findLoginByName(@PathVariable String loginName){
        return R.OK( loginLogService.findByName(loginName));
    }
//从缓存中获取状态为成功的数据
    @GetMapping("/login2/{loginName}")
    @ApiOperation("根据用户名获取日志")
    public R findLoginByName2(@PathVariable String loginName){
        return R.OK( loginLogService.findByLoginName(loginName));
    }


    @DeleteMapping("/login/{id}")
    @ApiOperation("根据id删除日志")
    public R deleteLoginLogById(@PathVariable Long id){
        loginLogService.deleteById(id);
        return R.OK();
    }
    @GetMapping("")
    public R findAllLoginLog(){
        return  R.OK(loginLogService.findAllSysLoginInFor());
    }
}
